﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CapaEntidades;
using System.Data;
using System.Data.SqlClient;

namespace CapaDatos
{
    public class datEstadia
    {
        #region singleton
        private static readonly datEstadia _instancia = new datEstadia();
        public static datEstadia Instancia
        {
            get { return datEstadia._instancia; }
        }
        #endregion

        #region "Metodos"
        public int RegistrarEstadia(String cadXML)
        {
            SqlCommand cmd = null;
            try
            {
                SqlConnection conex = Conexion.Instancia.Conectar();
                cmd = new SqlCommand("spInsertarEstadia", conex);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@prmcadXML", cadXML);
                conex.Open();
                int i = cmd.ExecuteNonQuery();
                return i;

            }
            catch(Exception e)
            {
                throw e;
            }
        }
        public List<entReserva> ListarReservaDelDia(String nroDocumento)
        {
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            List<entReserva> Lista = null;
            try
            {
                SqlConnection conex = Conexion.Instancia.Conectar();
                cmd = new SqlCommand("spListarReservasDelDia", conex);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@prmNroDoc", nroDocumento);
                conex.Open();
                dr = cmd.ExecuteReader();
                Lista = new List<entReserva>();
                while (dr.Read())
                {
                    entReserva r = new entReserva();
                    entPersona p = new entPersona(); 
                    r.IdReserva = Convert.ToInt32(dr["IDRESERVA"]);
                    p.IdPersona = Convert.ToInt32(dr["IDPERSONA"]);
                    r.Persona = p;
                    r.EstadoReserva = Convert.ToChar(dr["ESTADORESERVA"]);
                    r.FechaReserva = Convert.ToDateTime(dr["FECHARESERVA"]);
                    r.FechaEntrada = Convert.ToDateTime(dr["FECHAENTRADA"]);
                    r.FechaSalida = Convert.ToDateTime(dr["FECHASALIDA"]);
                    r.NroNoches = Convert.ToInt32(dr["NRONOCHES"]);
                    r.MontoPagado = Convert.ToDouble(dr["MONTOPAGADO"]);
                    r.Saldo = Convert.ToDouble(dr["SALDO"]);
                    Lista.Add(r);
                } 
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                cmd.Connection.Close();
            }
            return Lista;
        }
        #endregion
    }
}
